package com.tfswx.jcyw.sqlmodel.api.bean.table;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 张述江
 * @date 2023/9/15
 */
@Data
public class Join {
    private FromItem fromItem;
    private JoinType joinType;
    private Expression onExpression;

    public Join() {
        this(null);
    }

    public Join(FromItem fromItem) {
        this(JoinType.INNER, fromItem, null);
    }

    public Join(FromItem fromItem, Expression onExpression) {
        this(JoinType.INNER, fromItem, onExpression);
    }

    public Join(JoinType joinType, FromItem fromItem, Expression onExpression) {
        this.joinType = joinType;
        this.fromItem = fromItem;
        this.onExpression = onExpression;
    }

    public enum JoinType {
        INNER, LEFT, RIGHT, OUT;

        public static JoinType from(String type) {
            return Enum.valueOf(JoinType.class, type.toUpperCase());
        }
    }

    @Override
    public String toString() {
        return " " + joinType + " JOIN " + fromItem + " ON " + onExpression;
    }
}
